var config = require('../config/config')

var nodemailer = require('nodemailer')

var transporter = nodemailer.createTransport({
    host: "smtp.qq.com",
    secureConnection: true,
    port: 465,
    auth: {
        user: "1131029395@qq.com",
        pass: "ntxkwblzfkwdjagf"
    }
})

module.exports = {
    sendEmail: function(toEmail, subject, html) {
        var mailOptions = {
            from: config.siteEmail,
            to: toEmail,
            subject: subject,
            html: html
        }

        transporter.sendMail(mailOptions, (error, info) => {
            if (error) {
                return console.log(error)
            }
            console.log('Message %s sent: %s success', info.messageId, info.response)
        });
    }
}